﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace UtilsLib.UtilsDataAccess
{
    public static class SQLHelper
    {
        /// <summary>
        /// return the SQL prep String
        /// </summary>
        /// <param name="strRequete"></param>
        /// <returns></returns>
        public static string getPrepString(string strRequete)
        {
            string strRes;
            if (strRequete != null)
                strRes = "'" + strRequete.Replace("'", "''") + "'";
            else
                strRes = "''";
            return strRes;
        }

        /// <summary>
        /// Set the ISNULL sql function while preping the string for SQL query
        /// </summary>
        /// <param name="column"> The name of the column</param>
        /// <param name="valueNull">The value to set if the result is NULL</param>
        /// <returns>The SQL query</returns>
        public static string setIsNull(string column, string valueNull)
        {
            return ("ISNULL(" + column + ",") + "'" + (valueNull == "''" ? "" : valueNull) + "')";
        }

        /// <summary>
        /// Set the ISNULL sql function while preping the string for SQL query
        /// </summary>
        /// <param name="column"> The name of the column</param>
        /// <param name="valueNull">The value to set if the result is NULL</param>
        /// <returns>The SQL query</returns>
        public static string setIsNull(string column, int valueNull)
        {
            return "ISNULL(" + column + "," + valueNull  + ")";
        }

        public static string getPrepFloatToString(string number)
        {
            return number.Replace(",", ".");
        }

        public static int getPrepBool(bool bit)
        {
            return (bit ? 1 : 0);
        }
    }
}
